 var request_secre = false;
         	$(document).ready(function(){
             	$("#acountlist > li ").filter(":not(#addnewacount)").hover(function(){
                 		$(this).children("img").show();
                 	}, function(){
                 		$(this).children("img").hide();
                     	});


             	$("#addNewCo").click(function(){
                 		var p = $(this).offset();
                 		$("#addMenu").css({"left":p.left, "top":p.top + 100}).slideDown("fast");
                 	});
             	
             	$("#acountlist > li ").children(".acount_delete_bt").click(function(){
             		var acount_id = $(this).parent("li").children(".acount_id_span").html();
             		var acount_name = $(this).parent("li").children(".acount_name_span").html();
             		var acount_source = $(this).parent("li").children(".acount_source_span").html();
             		var dom = $(this).parent("li");
             		
             		if(confirm("你确定要删除的"+acount_source.trim()+"账号: " + acount_name.trim())){
             			
             			$.ajax({
            				  type: 'POST',
            				  url: "deleteacount.php",
            				  data: {action: 'delete', table: 'sns_acount', id: acount_id},
            				  success: function(data){
            					  dom.remove();
            					  $("#alert_box").css({'left': $(document).width()/2-100, 'top': $(document).height()/2-100,'background': '#339506'} );
            					  $("#alert_box").html(data);
                              	  $("#alert_box").fadeIn().delay(3000).fadeOut();
                              	  
                				  }
            				});
             		}
             		
             	});


             	$(document).click(function(event){
                 	var b = $(event.target).parentsUntil("#addMenu");
                 	if(b.get(b.length-1).tagName == "HTML" && $(event.target).attr("id") != "addNewCo"){
                     	var c = $("#addMenu").css("display");
                     	if(c == "block"){
                     		$("#addMenu").hide();
                     	}
                 	}
                 	});

             	$("#addMenu >ul >li").click(function(){
                 		var site = $(this).attr("id");
                 		if(site == "sina"){
                 			sinaAuth();
                 		}else if(site == "tencent"){
                 			tencentAuth();
                 			
                 		}
                 	});

             	var sinaAuth = function(){
                 	alert("sina");
                 	window.open('https://api.weibo.com/oauth2/authorize?client_id=2618546663&response_type=token&redirect_uri=http://yicosys.com/tool/social/tencentauth.php',
                         	'authWindow','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no'); 
             	};

             	var tencentAuth = function(){

                 	var tURL = window.singature({'action':'https://open.t.qq.com/cgi-bin/request_token' , 'oauth_callback': "http://yicosys.com/tool/social/tencentauth.php"});

        			$.ajax({
        				  type: 'POST',
        				  url: "sinaAuth.php",
        				  data: {url: tURL, action: 'requesttoken'},
        				  success: function(data){
            				 	var result = $.parseJSON(data);
            				 	window.open('https://open.t.qq.com/cgi-bin/authorize?oauth_token='+result.oauth_token); 
            				 	request_secre = result.oauth_token_secret;
            				  }
        				});
             	};
             	
             	});

         	function tencent_oauth(oauth_token, oauth_verifier){
             	var tURL = singature({'tokenSecret':request_secre, 'action':'https://open.t.qq.com/cgi-bin/access_token', 'oauth_token': oauth_token, 'oauth_verifier': oauth_verifier});
             	$.ajax({
  				  type: 'POST',
  				  url: "sinaAuth.php",
  				  data: {url: tURL, action: 'requesttoken'},
  				  success: function(data){
  						var result = $.parseJSON(data);
  						var sURL = singature({'action': 'http://open.t.qq.com/api/user/info', 'oauth_token':result.oauth_token, 'tokenSecret':result.oauth_token_secret, 'format': 'json'});
  						getTecentUserInfo(sURL, result.oauth_token, result.oauth_token_secret);
      				  }
  				});
             	}

         	function getTecentUserInfo(tURL, oauth_token, oauth_token_secret){
         		$.ajax({
  				  type: 'POST',
  				  url: "sinaAuth.php",
  				  data: {url: tURL, action: 'normal'},
  				  success: function(data){
  						var result = $.parseJSON(data);
  						if(result.ret == "0"){
  	  						var uid = $("#user_id_disnone").html();
  	  						saveAcount({'acount_id': result.data.openid, 'acount_name': result.data.name, 'acount_image':result.data.head + "/100",
  	  							'acount_source': 'tencent', 'oauth_acesstoken': oauth_token, 'oauth_acesssecret': oauth_token_secret,
  	  							'oauth_version': '1.0', 'uid':uid });
  						}else{
  	  						alert("获取用户信息失败！");
  						}
      				  }
  				});
         	}

         	function saveAcount(savedata){
             	$.ajax({
                 	type: 'POST',
                 	url: 'saveacountajax.php',
                 	data: savedata,
                 	success:  function(data){
                     	 var result = data.split(":");
                     	 if(result[0] == '0'){
	                     	$("#alert_box").css({'left': $(document).width()/2-100, 'top': $(document).height()/2-100,'background': '#339506'} );
	                     	addAcountToBody(savedata, result[2]);
                     	 }else{
                     		$("#alert_box").css({'left': $(document).width()/2-100, 'top': $(document).height()/2-100,'background': '#F1171B'} );
                     	 }
                     	 $("#alert_box").html(result[1]);
                     	 $("#alert_box").fadeIn().delay(3000).fadeOut();
                     	 $("#addMenu").hide();
                     	}
                 	});
         	}

         	function addAcountToBody(data, id){
             	var html = "<li>";
             	html += "<span class=\"acount_id_span\" style=\"display: none;\">"+id+"</span>";
				html += "<span class=\"acount_name_span\" style=\"display: none;\">"+data.acount_name+"</span>";
				html += "<span class=\"acount_source_span\" style=\"display: none;\">"+(data.acount_source == 'tencent'? '腾讯微博' : '新浪微博')+"</span>";
        		html +=	"<img src=\"images/delete.png\"  style=\"float: right; margin: -10px; display: none;\" />";
				html += "<div>";
				html +=	"<img class=\"touxiang\" src=\""+ data.acount_image +"\"  />";
				html +=	"<span>"+ data.acount_name +"</span>";
				html += "</div>";
				html += "<div class=\"weibosign\"><img src=\"";
				if(data.acount_source == 'tencent')
					html +=	"images/tencent.png\"  />腾讯微博</div>";
				if(data.acount_source == 'sina')
					html +=	"images/sina.png\"  />新浪微博</div>";
				html += "</li>";

				$("#addnewacount").before(html);
         	}

         	var singature = function (options, para){
         		var accessor = { consumerSecret: "74eb3de422889cc6097fccfcf715aecb"
                    , tokenSecret : options.tokenSecret};
	         	var message = {
	                 	method: "GET",
	                 	action: options.action,
	                 	parameters: [
	                 		["oauth_version", "1.0"],
	                 		["oauth_consumer_key","801084374"],
	                 		["oauth_timestamp",OAuth.timestamp()],
	                 		["oauth_nonce", OAuth.nonce(32)],
	                 		["oauth_signature_method", "HMAC-SHA1"],
	                     	]
	                 	};

             	if(options.oauth_token){
                 	message.parameters.push(['oauth_token', options.oauth_token]);
             	}
             	if(options.oauth_verifier){
             		message.parameters.push(['oauth_verifier', options.oauth_verifier]);
             	}
             	if(options.oauth_callback){
             		message.parameters.push(['oauth_callback', options.oauth_callback]);
             	}
             	if(options.format){
             		message.parameters.push(['format', options.format]);
             	}
             	
             	OAuth.SignatureMethod.sign(message, accessor);
             	var signcode = OAuth.getParameter(message.parameters, "oauth_signature");
             	if(signcode.toString().indexOf("+") != -1){
             		return singature(options);
             	}else{
             		var tURL = options.action + "?"+OAuth.SignatureMethod.normalizeParameters(message.parameters).replace(/oauth_signature/,"oauth_signature="+OAuth.getParameter(message.parameters, "oauth_signature")+"&oauth_signature");
             		return tURL;
             	}
	         	
         	};
         	